package be.vdab.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import be.vdab.dao.KlantenDAO;
import be.vdab.entities.Klanten;

/**
 * Servlet implementation class BevestigServlet
 */
@WebServlet("/bevestiging.htm")
public class BevestigServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String VIEW = "/WEB-INF/JSP/bevestiging.jsp";
	//private static final String REDIRECT_VIEW = "/bevestiging.htm";
	

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getRequestDispatcher(VIEW).forward(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Klanten klant = null;
		KlantenDAO klantenDAO = new KlantenDAO();
		HttpSession session = null;		
		String gebruikersnaam = request.getParameter("Gebruikersnaam");
		String paswoord = request.getParameter("Paswoord");
		klant = klantenDAO.zoekGebruiker(gebruikersnaam, paswoord);
		if(klant != null){			
			request.setAttribute("klant", klant);
			session= request.getSession();
			session.setAttribute("klant", klant);
		}
		else{
			String fout = "de combinatie gebruikersnaam - paswoord is niet juist";
			request.setAttribute("fout", fout);
		}
		request.getRequestDispatcher(VIEW).forward(request, response);
	}
}
